#include <string>
#include <map>
#include <iostream>
#include "tinyxml.h"
#include "CvVision.h"

#ifdef WIN32
#include <direct.h>
#else
#include<sys/stat.h>
#include<sys/types.h>
#endif
//#include <stdlib.h>
//#include <stdio.h>

//This class is the only clean code there is anymore in this project.
//So be nice with it.

class DATReader
{
public:
	DATReader()
	{
		mDATDoc = NULL;
		mVideoFeed = NULL;
		mStartingFrame = 0; //if no starting frame is given, its start at 0... good luck with that

		double lHScale=0.5;
		double lVScale=0.5;
		int    lLineWidth=1;
		cvInitFont(&mFont,CV_FONT_HERSHEY_SIMPLEX, lHScale,lVScale,0,lLineWidth);
	}
	~DATReader()
	{
		if(mDATDoc)
			delete mDATDoc;
		if(mVideoFeed)
			delete mVideoFeed;
	}
	//Colors functions
	void setColorScheme(std::map<std::string,CvScalar> inColors){mColors=inColors;};	//Deep copy... bad
	void addColor(std::string inObjectType,CvScalar inColor){mColors[inObjectType]=inColor;}

	//Load functions
	bool loadXMLFile(std::string inFilename);	//Only open the file and check if ok
	bool loadVideoFeed(std::string inFilename);	//Please, know what your doing
	void setStartingFrame(unsigned int inStartingFrame){mStartingFrame=inStartingFrame;};
	
	//	If  you want to make "it" BIGGER or _smaller_
	void changeFont(int inFontFace, double inHScale, double inVScale, double inShear CV_DEFAULT(0), 
					int inThickness CV_DEFAULT(1), int inLineType CV_DEFAULT(8))
	{
		cvInitFont(&mFont,inFontFace,inHScale,inVScale,inShear,inThickness,inLineType);	
	}

	//If save <= -2 : Do not save
	//if save == -1 : Save in png (yeah, i dont permit the prompt)
	//if save >= 0 : Use fourcc
	//Will use the XML filename + timestamp for directory or filename
	//Read all the objects, even the minus one if inShowUndead is false...
	bool playXML(int inSave=-2,bool inInteractive=true,bool inReadAll=false, bool inShowUndead=false);		
	
	
private:
	bool checkFile();				//Check if the format of the XML file's ok;

	TiXmlDocument*					mDATDoc;
	CvVision*						mVideoFeed;
	unsigned int					mStartingFrame;

	CvFont							mFont;

	//color scheme
	std::map<std::string,CvScalar>	mColors;
};